package com.ssy.lingxi.contract.repository;

import com.ssy.lingxi.contract.entity.PurchaseInviteBidDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * 采购招标合同
 * @author 伍将
 * @date 2021/3/5
 * @version 2.0.0
 */
public interface PurchaseInviteBidRepository extends JpaRepository<PurchaseInviteBidDO, Long>, JpaSpecificationExecutor<PurchaseInviteBidDO> {

    /**
     * 查询采购招标合同
     * @author 伍将
     * @date 2021/3/5
     * @param inviteBidMemberId: 招标会员id
     * @param inviteBidRoleId: 招标会员角色id
     * @param inviteBidId: 招标单id
     * @param bidWinnerMemberId: 中标会员id
     * @param bidWinnerRoleId: 中标会员角色id
     * @return 采购招标合同
     **/
    @Query(value = "select * from con_purchase_invite_bid " +
            "where invite_bid_member_id =:inviteBidMemberId and invite_bid_role_id =:inviteBidRoleId " +
            "and invite_bid_id =:inviteBidId " +
            "and bid_winner_member_id =:bidWinnerMemberId and bid_winner_role_id =:bidWinnerRoleId " +
            "limit 1", nativeQuery = true)
    PurchaseInviteBidDO findData(Long inviteBidMemberId, Long inviteBidRoleId, Long inviteBidId, Long bidWinnerMemberId, Long bidWinnerRoleId);

    /**
     * 查询已被创建合同的采购招标合同
     * @author 伍将
     * @date 2021/3/5
     * @param inviteBidMemberId: 招标会员id
     * @param inviteBidRoleId: 招标会员角色id
     * @param inviteBidId: 招标单id
     * @param bidWinnerMemberId: 中标会员id
     * @param bidWinnerRoleId: 中标会员角色id
     * @return 采购招标合同
     **/
    @Query(value = "select * from con_purchase_invite_bid " +
            "where invite_bid_member_id =:inviteBidMemberId and invite_bid_role_id =:inviteBidRoleId " +
            "and invite_bid_id =:inviteBidId " +
            "and bid_winner_member_id =:bidWinnerMemberId and bid_winner_role_id =:bidWinnerRoleId " +
            "and is_create =1 " +
            "limit 1", nativeQuery = true)
    PurchaseInviteBidDO findCreateData(Long inviteBidMemberId, Long inviteBidRoleId, Long inviteBidId, Long bidWinnerMemberId, Long bidWinnerRoleId);
}
